﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Game;


namespace Indie_Game_Contest
{
    class GameplayState : IGameState
    {
        //////////////////////////////////////////////////////////////////////////
        // Data Members
        static GameplayState instance = new GameplayState();
        ObjectManager om = ObjectManager.Instance;
        TextureManager tm = TextureManager.Instance;
        MessageSystem ms = MessageSystem.Instance;
        HUD _hud = HUD.Instance;
        Platform platform1 = new Platform();

        // Waves
        int    nWave = 1;
        int    numEnemies = 0;
        int    numDeadEnemies = 0;
        int    whenToSpawn = 0;
        float  spawnTimer = 0;
        bool   beginWave = true;
        bool   stopWord = false;
        float  timer = 0.0f;
        Random rand = new Random();

        //////////////////////////////////////////////////////////////////////////
        // Assets
        int fontID;
        int explosionID;
        int playerID;
        int enemyID;
        int foxenemyID;
        int BoxerenemyID;
        Fox foxy;
        Boxer boxy;

        Player player = new Player();

        //////////////////////////////////////////////////////////////////////////
        // Methods
        GameplayState() { }

        override public void Enter()
        {
            // Load assets needed
            WorldData.spriteBatch.GraphicsDevice.Reset();
            ms.MsgProc = MsgProc;
            CInput.Instance.Clear();

          
            _hud.Enter();
            _hud.Num_health = player.Player_health;
            _hud.Num_lives = player.Player_live;
            _hud.Score = player.Score;
            Tile t = new Tile();
            t.Rect = new Rectangle(0, 0, 16, 16);
            t.Position = new Vector2(200, 430);
            t.TextureID = explosionID;
            t.Width = TextureManager.Instance.GetTexture(explosionID).Width;
            t.Height = TextureManager.Instance.GetTexture(explosionID).Height;
            WorldData.spriteBatch.GraphicsDevice.Reset();
            player.Collision = true;
            player.TextureID = playerID;
            player.Walk = new CatAnimations();
            player.Jumping = new CatAnimations();
            player.Idle = new CatAnimations();
            player.Attack1 = new CatAnimations();
            player.Combo2 = new CatAnimations();
            player.Combo3 = new CatAnimations();
            player.Walk.LoadSpiteData(TextureManager.Instance.GetTexture(IntroState.Instance.Cats), 6, 10, 3, 50, 50);
            player.Jumping.LoadSpiteData(TextureManager.Instance.GetTexture(IntroState.Instance.Cats), 6, 10, 4, 50, 50);
            player.Idle.LoadSpiteData(TextureManager.Instance.GetTexture(IntroState.Instance.Cats), 6, 10, 4, 50, 50);
            player.Attack1.LoadSpiteData(TextureManager.Instance.GetTexture(IntroState.Instance.Cats), 6, 10, 3, 50, 50);
            player.Combo2.LoadSpiteData(TextureManager.Instance.GetTexture(IntroState.Instance.Cats), 6, 10, 2, 50, 50);
            player.Combo3.LoadSpiteData(TextureManager.Instance.GetTexture(IntroState.Instance.Cats), 6, 10, 4, 50, 50);

            player.Width = player.Walk.Width - 15;
            player.Height = player.Walk.Height;
            player.Scale = 1.7f;
            player.Center = new Vector2(player.Width / 2, player.Height / 2);
            player.Position = new Vector2(30, 150);
            player.Player_health = 80.0f;
            player.Player_live = 1;
            om.AddObject(t);
            om.AddObject(player);

            //////////////////////////////////////////////////////////////////////////
            // Loading Tiles
            TextureManager tManager = TextureManager.Instance;
            CTileManager tileManager = CTileManager.Instance;
            Tile tile = new Tile();
            tile.LoadContent(new Rectangle(104,88,32,32), new Vector2(100, 450-16), Color.White, tm.GetTexture(0), 0.0f, 1.0f, 32, 32, 0);
            tile.Width = 32;
            tile.Height = 32;
            tile.Collision = true;
            om.AddObject(tile);
           // int nID = tManager.AddTexture(Content.Load<Texture2D>("background_32"));

            //////////////////////////////////////////////////////////////////////////
            //
            nWave = 1;
            numEnemies = 0;
            numDeadEnemies = 0;
            whenToSpawn = 0;
            spawnTimer = 0;
            beginWave = true;
            stopWord = false;
            timer = 0.0f;
            player.Score = 0;
            
            //  int nX = 0; int nY = 120;
            int nX = -10;
            int nY = WorldData.WindowHeight - tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Height + 35;

   

            //tManager.GetTexture(0);
            Tile ti = new Tile();


            for (int i = 0; i < 34; ++i)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]),
                    0.0f, 1.0f, tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Height, CTileManager.Instance.TileIDs["ground"]);
               // ti.NCurrentTile = (int)TilesSet.SINGLE;
               // ti.SelectTileToUse(ti.NCurrentTile);
                ti.Collision = true;
                om.AddObject(ti);
                nX += tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Width-22;

                if (nX > WorldData.WindowWidth  )
                {
                    ti = new Tile();
                    ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]),
                    0.0f, 1.0f, tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["ground"]).Height, CTileManager.Instance.TileIDs["ground"]);
                    // ti.NCurrentTile = (int)TilesSet.SINGLE;
                    // ti.SelectTileToUse(ti.NCurrentTile);
                    ti.Collision = true;
                    om.AddObject(ti);

                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }

            nX += 32; 
            nY -= 20;
            for (int i = 0; i < 12; i+=6)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["shroom"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["shroom"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["shroom"]),
                    0.0f, 1.0f, tManager.GetTexture(CTileManager.Instance.TileIDs["shroom"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["shroom"]).Height, CTileManager.Instance.TileIDs["shroom"]);
                // ti.NCurrentTile = (int)TilesSet.SINGLE;
                // ti.SelectTileToUse(ti.NCurrentTile);
                ti.Collision = false;
                om.AddObject(ti);
                nX += tManager.GetTexture(CTileManager.Instance.TileIDs["shroom"]).Width + 128;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }

            nX += 40;
            nY -= 55; 
            for (int i = 0; i < 1; ++i )
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["hill_long"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["hill_long"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["hill_long"]),
                    0.0f, 1.0f, tManager.GetTexture(CTileManager.Instance.TileIDs["hill_long"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["hill_long"]).Height, CTileManager.Instance.TileIDs["hill_long"]);
                // ti.NCurrentTile = (int)TilesSet.SINGLE;
                // ti.SelectTileToUse(ti.NCurrentTile);
                ti.Collision = false;
                om.AddObject(ti);
                nX += tManager.GetTexture(CTileManager.Instance.TileIDs["hill_long"]).Width + 128;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }

            nX += 80;
            nY += 23;
            for (int i = 0; i < 1; ++i)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["hill_short"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["hill_short"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["hill_short"]),
                    0.0f, 1.0f, tManager.GetTexture(CTileManager.Instance.TileIDs["hill_short"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["hill_short"]).Height, CTileManager.Instance.TileIDs["hill_short"]);
                // ti.NCurrentTile = (int)TilesSet.SINGLE;
                // ti.SelectTileToUse(ti.NCurrentTile);
                ti.Collision = false;
                om.AddObject(ti);
                nX += tManager.GetTexture(CTileManager.Instance.TileIDs["hill_short"]).Width + 64;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }


            nX -= 40;
            nY += 55; 

                nX = 100;
                nY -= 100;

            //////////////////////////////////////////////////////////////
            //  Platform Test
                Vector2 vPos = Vector2.Zero;
                Vector2 vMin = Vector2.Zero;
                Vector2 vMax = Vector2.Zero;
                Vector2 vVel = Vector2.Zero;

                vPos.X = nX;
                vPos.Y = nY - 10;
                platform1.VPlatform = vPos;

                vMin.X = 250;
                vMax.X = WorldData.WindowWidth - 200;

                vMin.Y = vPos.Y - 50.0f;
                vMax.Y = vPos.Y;

                vVel.X = 50.0f;
                vVel.Y = 0.0f;

                platform1.VMaxLimit = vMax;
                platform1.VMinLimit = vMin;
                platform1.VVelocity = vVel;


            for (int i = 0; i < 10; ++i)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["ground_cave"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["ground_cave"]).Height),
                    new Vector2(nX, vPos.Y), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["ground_cave"]),
                    0.0f, 0.5f, tManager.GetTexture(CTileManager.Instance.TileIDs["ground_cave"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["ground_cave"]).Height, CTileManager.Instance.TileIDs["ground_cave"]);
                platform1.AddTile(ti);
                nX += (int)(ti.Width*ti.Scale) - 22;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }

            om.AddPlatform(platform1);
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            platform1 = new Platform();

            nX = 0;
            nY -= 125;

            vPos.X = nX;
            vPos.Y = nY;
            platform1.VPlatform = vPos;

            vMin.X = 100;
            vMax.X = WorldData.WindowWidth - 100;

            vMin.Y = 50;
            vMax.Y = WorldData.WindowHeight - 150;

            vVel.X = 0.0f;
            vVel.Y = 0.0f;

            platform1.VMaxLimit = vMax;
            platform1.VMinLimit = vMin;
            platform1.VVelocity = vVel;


            for (int i = 0; i < 15; ++i)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["block"]),
                    0.0f, 0.5f, tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Height, CTileManager.Instance.TileIDs["block"]);
                platform1.AddTile(ti);
                nX += (int)(ti.Width * ti.Scale) - 22;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }
            om.AddPlatform(platform1);
            platform1 = new Platform();

            platform1 = new Platform();

            nX += 415;
           // nY -= 125;

            vPos.X = nX;
            vPos.Y = nY;
            platform1.VPlatform = vPos;

            vMin.X = 100;
            vMax.X = WorldData.WindowWidth - 100;

            vMin.Y = 50;
            vMax.Y = WorldData.WindowHeight - 150;

            vVel.X = 0.0f;
            vVel.Y = 0.0f;

            platform1.VMaxLimit = vMax;
            platform1.VMinLimit = vMin;
            platform1.VVelocity = vVel;


            for (int i = 0; i < 15; ++i)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Height),
                    new Vector2(nX, nY), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["block"]),
                    0.0f, 0.5f, tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["block"]).Height, CTileManager.Instance.TileIDs["block"]);
                platform1.AddTile(ti);
                nX += (int)(ti.Width * ti.Scale) - 22;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }
            om.AddPlatform(platform1);
            platform1 = new Platform();

            //////////////////////////////////////////////////////////////////////////////////////////////////////
            //  Cloud Test
            vPos.X = WorldData.WindowWidth / 2 ;
            vPos.Y = tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]).Height ;
            platform1.VPlatform = vPos;
           // platform1.BNegateVelocityX = false;

            vMin.X = -tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]).Width + 50 ;
            vMax.X = WorldData.WindowWidth;

            vMin.Y = 25;
            vMax.Y = 100;

            vVel.X = 10.0f;
            vVel.Y = 0.0f;

            platform1.VMaxLimit = vMax;
            platform1.VMinLimit = vMin;
            platform1.VVelocity = vVel;

            for (int i = 0; i < 1; ++i)
            {
                ti.LoadContent(new Rectangle(0, 0, tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]).Height),
                    new Vector2(vPos.X, vPos.Y), Color.White, tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]),
                    0.0f, 0.5f, tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]).Width,
                    tManager.GetTexture(CTileManager.Instance.TileIDs["cloud_1"]).Height, CTileManager.Instance.TileIDs["cloud_1"]);
                platform1.AddTile(ti, false );
                nX += (int)(ti.Width * ti.Scale) - 22;

                if (nX > WorldData.WindowWidth)
                {
                    nX = 0;
                    nY -= 32;
                }
                ti = new Tile();

            }
            om.AddPlatform(platform1);
            platform1 = new Platform();


            AudioManager.Instance.PlaySong("Game Music", true);

        }


        override public void Exit()
        {
            om.Dispose();
            ms.Dispose();
        }

        override public void Render()
        {

            om.Render();
            WorldData.spriteBatch.Draw(TextureManager.Instance.GetTexture(CTileManager.Instance.TileIDs["curtains"]),
                new Rectangle(-15, 0, WorldData.WindowWidth+30, WorldData.WindowHeight+25), Color.White);
            _hud.Draw();

            if (beginWave)
            {
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(fontID), "Act " + nWave,
                new Vector2(360, WorldData.WindowHeight / 2 - 128 + timer * 200), Color.DarkBlue);
            }
            else if(stopWord)
            {
                WorldData.spriteBatch.DrawString(TextureManager.Instance.GetSpriteFont(fontID), "Act " + nWave,
                new Vector2(360, WorldData.WindowHeight / 2 - 128 + 200), Color.DarkBlue);
            }
        }
        override public void Update(float dt)
        {
           // platform1.UpdatePlatform(dt);
            //Player.Velocity.X = pla
            om.Update(dt);
            om.CheckCollisions();
            _hud.Update();
            _hud.Num_health = (int)player.Player_health;
            _hud.Num_lives = player.Player_live;
            _hud.Score = player.Score;

            HandleGame(dt);
            ms.ProcessMessages();
        }
        override public bool Input()
        {
            // Pause Game
            if (CInput.Instance.KeyDown(Keys.Escape) || CInput.Instance.GamePadButtonPressed(Buttons.Start))
                Game1.Instance.AddState(PauseState.Instance);

            return true;
        }

        void HandleGame(float dt)
        {
            if (beginWave)
            {

                timer += dt;

                if (timer > 1)
                {
                    beginWave = false;
                    stopWord = true;
                }
            }
            else if (stopWord)
            {
                timer += dt;

                if (timer > 2)
                {
                    timer = 0;
                    stopWord = false;
                }
            }
            else if(numEnemies < nWave*2)
            {
                spawnTimer += dt;

                if (spawnTimer >= whenToSpawn || numDeadEnemies >= numEnemies)
                {
                    spawnTimer = 0;
                    whenToSpawn = rand.Next(3);

                    MessageSystem.Instance.SendMessage(new CreateEnemyMessage());
                    ++numEnemies;
                }
            }
            else if(numEnemies >= nWave * 2 && numDeadEnemies >= numEnemies)
            {
                whenToSpawn = 3;
                spawnTimer = 0;
                numEnemies = 0;
                numDeadEnemies = 0;
                beginWave = true;
                timer = 0;
                ++nWave;

                Vector2 vLocal = om.GetPlatform(0).VVelocity;

                if (vLocal.X > 300.0f)
                {
                    vLocal.Y += 10.0f;
                }
                else
                    vLocal.X *= 2.0f;

                om.GetPlatform(0).VVelocity = vLocal;
                AudioManager.Instance.PlaySFX("cheer");
            }
        }

        // Message Proc
        static void MsgProc(IMessage msg)
        {
            switch (msg.ID)
            {
                case MessageID.CreateEnemy:
                    {
                       //Enemy enmy = new Enemy();
                        
                        Random rand = new Random();
                        Vector2 position= Vector2.Zero;
                        int coin = rand.Next(2);
                        if (coin == 0)
                        {
                            Fox foxy = new Fox();
                            //////////////////////////////////////////////////////////////////////////
                            // Get a random spawn\f
                            if (rand.Next(2) == 0)
                                position.X = -16;
                            else
                                position.X = WorldData.WindowWidth + 16;

                            if (rand.Next(2) == 0)
                                position.Y = WorldData.WindowHeight - 150;
                            else
                                position.Y =  50-82;
                            //

                            // Create the enemy
                            foxy.LoadContent(new Rectangle(0, 0, 56, 82), position, Color.White,
                                TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID), 0, .85f, 
                                TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID).Width / 3, TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID).Height/9, GameplayState.Instance.FoxenemyID);
                            foxy.Idle = new EnemyAnimation();
                            foxy.Walking = new EnemyAnimation();
                            foxy.Damaged = new EnemyAnimation();
                            foxy.Attack = new EnemyAnimation();
                            foxy.Collision = true;
                            foxy.Enemy_Dead = new EnemyAnimation();
                            foxy.Health = 100.0f;
                            foxy.Idle.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID), 9, 3, 3, 56, 82);
                            foxy.Walking.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID), 9, 3, 3, 56, 82);
                            foxy.Damaged.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID), 9, 3, 3, 56, 82);
                            foxy.Attack.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID), 9, 3, 3, 56, 82);
                            foxy.Enemy_Dead.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.FoxenemyID), 9, 3, 3, 56, 82);
                        //position.X = 400;
                            ObjectManager.Instance.AddObject(foxy);
                        }
                        else
                        {
                            if (rand.Next(2) == 0)
                                position.X = -16;
                            else
                                position.X = WorldData.WindowWidth + 16;

                            if (rand.Next(2) == 0)
                                position.Y = WorldData.WindowHeight - 150;
                            else
                                position.Y = 50-117;
                            Boxer boxy = new Boxer();
                            boxy.LoadContent(new Rectangle(0, 0, 56, 117), position, Color.White, TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID),
                                0.0f, .85f, TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID).Width / 3 - 5, ((TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID).Height / 9)/2)-10, GameplayState.Instance.BoxerenemyID);
                            boxy.Idle = new EnemyAnimation();
                            boxy.Walking = new EnemyAnimation();
                            boxy.Damaged = new EnemyAnimation();
                            boxy.Attack = new EnemyAnimation();
                            boxy.Enemy_dead = new EnemyAnimation();
                            boxy.Collision = true;
                            boxy.Health = 100.0f;

                            boxy.Idle.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID), 9, 3, 3, 56, 117);
                            boxy.Walking.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID), 9, 3, 3, 56, 117);
                            boxy.Damaged.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID), 9, 3, 3, 56, 117);
                            boxy.Attack.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID), 9, 3, 3, 56, 117);
                            boxy.Enemy_dead.LoadSpiteData(TextureManager.Instance.GetTexture(GameplayState.Instance.BoxerenemyID), 9, 3, 3, 56, 117);
                            ObjectManager.Instance.AddObject(boxy);

                        }

                        break;
                    }
                case MessageID.PlayerDead:
                    {
                        if (GameplayState.instance.player.Player_health <= 0)
                        {
                            PlayerDeadMessage pMsg = (PlayerDeadMessage)msg;

                            AudioManager.Instance.PlaySFX("meow");
                            GameplayState.Instance.player.Player_live -= 1;
                            GameplayState.Instance.player.Player_health = 100.0f;

                            if (GameplayState.Instance.player.Player_live < 0)
                            {
                                //////////////////////////////////////////////////////////////////////////
                                // GAME OVER
                                if (GameplayState.Instance.player.Score > HUD.Instance.HighScore)
                                    HUD.Instance.HighScore = GameplayState.Instance.player.Score;

                                AudioManager.Instance.StopSFX("meow");


                                Game1.Instance.AddState(GameOverState.Instance);
                            }
                        }
                        
                    }
                    break;
                case MessageID.EnemyDead:
                    {
                        EnemyDeadMessage eMsg = (EnemyDeadMessage)msg;
                        ++GameplayState.Instance.numDeadEnemies;
                        GameplayState.Instance.Player.Score += 100;
                        GameplayState.Instance.player.IncreaseGossip(10);
                        ObjectManager.Instance.RemoveObject(eMsg.Obj);
                    }
                    break;
                default:
                    break;
            }
        }

        //////////////////////////////////////////////////////////////////////////
        // Properties
        public int EnemyID
        {
            get { return enemyID; }
            set { enemyID = value; }
        }
        public int PlayerID
        {
            get { return playerID; }
            set { playerID = value; }
        }
        public int ExplosionID
        {
            get { return explosionID; }
            set { explosionID = value; }
        }
        public int FontID
        {
            get { return fontID; }
            set { fontID = value; }
        }
        public static Indie_Game_Contest.GameplayState Instance
        {
            get { return instance; }
        }
        public Indie_Game_Contest.Player Player
        {
            get { return player; }
            set { player = value; }
        }
        public int FoxenemyID
        {
            get { return foxenemyID; }
            set { foxenemyID = value; }
        }
        public int BoxerenemyID1
        {
            get { return BoxerenemyID; }
            set { BoxerenemyID = value; }
        }
    }
}
